Public Class ObjUtilsEvent
    Private lst As ArrayList
    Dim txt As TextBox
    Dim cbo As Infragistics.Win.UltraWinGrid.UltraCombo
    Dim udtp As Infragistics.Win.UltraWinSchedule.UltraCalendarCombo
    Dim dtp As DateTimePicker
    Dim utg As Infragistics.Win.UltraWinGrid.UltraGrid
    Public Sub New()
        lst = New ArrayList
    End Sub
    Public Event MyEvent()
    Public Sub addObjUtilsect(ByVal obj As ObjUtils)
        lst.Add(obj)
    End Sub
    Public Function getListObjUtilsect() As ArrayList
        Return lst
    End Function
    Public Sub execute()
        For index As Integer = 0 To lst.Count - 1
            If TypeOf lst.Item(index) Is TextBox Then
                txt = CType(lst.Item(index), TextBox)
                AddHandler txt.KeyPress, AddressOf KeyPressEnter
            End If
            If TypeOf lst.Item(index) Is Infragistics.Win.UltraWinGrid.UltraCombo Then
                cbo = CType(lst.Item(index), Infragistics.Win.UltraWinGrid.UltraCombo)
                AddHandler cbo.KeyPress, AddressOf KeyPressEnter
            End If
            If TypeOf lst.Item(index) Is Infragistics.Win.UltraWinSchedule.UltraCalendarCombo Then
                udtp = CType(lst.Item(index), Infragistics.Win.UltraWinSchedule.UltraCalendarCombo)
                AddHandler udtp.KeyPress, AddressOf KeyPressEnter
            End If
            If TypeOf lst.Item(index) Is DateTimePicker Then
                dtp = CType(lst.Item(index), DateTimePicker)
                AddHandler dtp.KeyPress, AddressOf KeyPressEnter
            End If
            If TypeOf lst.Item(index) Is Infragistics.Win.UltraWinGrid.UltraGrid Then
                utg = CType(lst.Item(index), Infragistics.Win.UltraWinGrid.UltraGrid)
                'AddHandler utg.KeyPress, AddressOf KeyPressEnter
                AddHandler utg.KeyDown, AddressOf KeyDownEnter
            End If
        Next
    End Sub

    Sub RaiseMyEvent()
        '
        ' Method to raise the event.
        '
        RaiseEvent MyEvent()
    End Sub
    'Public Sub KeyDownEnter(ByVal sender As ObjUtilsect, ByVal e As System.Windows.Forms.KeyEventArgs)
    '    If Asc(e.KeyChar) = Keys.Enter Then
    '        SendKeys.Send("{TAB}")
    '        e.Handled = True
    '    End If
    'End Sub
    Public Sub KeyPressEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        If Asc(e.KeyChar) = Keys.Enter Then
            SendKeys.Send("{TAB}")
            e.Handled = True
        End If
    End Sub
    Public Sub KeyDownEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.KeyCode = Keys.Enter Then
            'Try
            utg.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.NextCell)
            utg.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditModeAndDropdown)
            e.Handled = True
            'Catch ex As Exception
            'End Try
        Else
            utg.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditModeAndDropdown)
            e.Handled = False
        End If
        If (e.KeyCode = Keys.Up) Or (e.KeyCode = Keys.Down) Then
            'MessageBox.Show("false")
            'Return False
        Else
            'MessageBox.Show("true")
            'Return True
        End If
    End Sub
    Public Sub Click(ByVal sender As Object, ByVal e As System.EventArgs)
        With cbo
            .Textbox.SelectionStart = 0
            .Textbox.SelectionLength = Len(.Text)
            .Focus()
        End With
    End Sub
    Public Sub NumericValuesOnly(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        Select Case Asc(e.KeyChar)
            Case AscW(ControlChars.Cr) 'Enter key
                e.Handled = True
            Case AscW(ControlChars.Back) 'Backspace
            Case 45, 46, 48 To 57 'Negative sign, Decimal and Numbers
            Case Else ' Everything else
                e.Handled = True
        End Select
    End Sub
End Class


